// 1.用Promise实现
// 2.图片加载成功，则插入body 图片加载失败，console；

function loadImg(url) {
    return new Promise((resolve, reject) => {
        const img = new Image();
        img.src = url;
        
        img.onload = () => {
            resolve(img);
        }

        img.onerror = (err) => {
            reject(err);
        }
    })
}

loadImg(url).then(value => 
    document.body.appendChild(value)
).catch(err => 
    console.error(err)
)
